﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using NHunspell;
using System.Reflection;

namespace SanctusSoftware.Spelling
{
  public class HunspellDictionary : IDictionary
  {

    Hunspell _Hunspell = null;

    public HunspellDictionary()
    {
      string path = GetDictionariesFolder(); // @"C:\Files\Sanctus Software\Projects\Chord Sheet Editor for Word\Dev\Main\Components\OpenOffice.org Dictionaries\en_EN-pack\en_US";
      string aff = Path.Combine(path, "en_US.aff");
      string dic = Path.Combine(path, "en_US.dic");
      _Hunspell = new Hunspell(aff, dic);
    }


    #region IDictionary Members

    public bool IsWordInDictionary(string word)
    {
      return _Hunspell.Spell(word);
    }

    #endregion

    #region Helper Functions

    protected string GetDictionariesFolder()
    {
      return Path.Combine(Assembly.GetExecutingAssembly().Location, "Dictionaries");
    }


    #endregion

  }
}
